package com.ele.Filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebFilter("/*")
public class CorsFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse resp = (HttpServletResponse) servletResponse;
        //允许的域名
        resp.setHeader("Access-Control-Allow-Origin", "*");
        //允许的请求方式
        resp.setHeader("Access-Control-Allow-Methods","*");
        //允许的请求中携带的那些请求头信息
        resp.setHeader("Access-Control-Allow-Headers","*");
        filterChain.doFilter(servletRequest,resp);
    }
}
